package utils

import (
	"fmt"
	"strings"
)

func FormatQuery(url string, paramName string) string {
	urls := strings.Split(url, "?")
	fmt.Printf("%+v", urls)
	if len(urls) < 2 {
		return ""
	}

	strParam := urls[1]
	strArr := strings.Split(strParam, "&")
	OutMap := make(map[string]interface{})
	if strArr[0] != "" && len(strArr) > 0 {
		for _, str := range strArr {
			newArr := strings.Split(str, "=")
			key := newArr[0]
			value := newArr[1]
			OutMap[key] = value
		}
	}
	return fmt.Sprintf("%v", OutMap[paramName])
}

func ConvertIntToBool(realVal int, defaultValue bool) bool {
	if realVal == 1 {
		return true
	}
	if realVal == -1 {
		return false
	}
	return defaultValue
}
